package com.boc.langxiang.presenter.me;

import com.boc.langxiang.contract.me.LeaveFeedBackAndListContract;
import com.boc.langxiang.entity.request.FeedBackListRequest;
import com.boc.langxiang.entity.request.FeedBackRequest;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.FeedbackListContent;
import com.boc.langxiang.entity.response.LeaveContentList;
import com.boc.langxiang.net.ApiService;
import com.boc.langxiang.net.HandleErrorSubscriber;
import com.boc.langxiang.net.NetClient;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class LeaveFeedBackPresenter implements LeaveFeedBackAndListContract.Presenter {

    private final ApiService mService;
    LeaveFeedBackAndListContract.View mView;


    public LeaveFeedBackPresenter(LeaveFeedBackAndListContract.View view) {
        mService = NetClient.getInstance().net().create(ApiService.class);
        this.mView = view;
    }

    /**
     * 回复
     *
     * @param content
     */
    @Override
    public void feedback(String content,String ispic) {
        FeedBackRequest feedBackRequest = new FeedBackRequest();
        feedBackRequest.content = content;
        feedBackRequest.ispic = ispic;
        mService.feedback(feedBackRequest.params()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new HandleErrorSubscriber<BaseResponse>(mView) {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        mView.setTextContentSuccess();
                    }
                });
    }

    /**
     * 列表
     */
    @Override
    public void feedbackList(String page) {
//        mView.showLoading();
        FeedBackListRequest feedBackListRequest = new FeedBackListRequest();
        feedBackListRequest.page = page;
        mService.feedbackList(feedBackListRequest.params()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new HandleErrorSubscriber<BaseResponse<FeedbackListContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<FeedbackListContent> response) {
                        FeedbackListContent content = response.getContent();
                        String count = content.getCount();
                        List<LeaveContentList> list = content.getList();
                        mView.getFeedbackList(list,count);
                    }
                });
    }

    @Override
    public void loadMore(String page) {
     /*   mView.showLoading();
        FeedBackListRequest feedBackListRequest = new FeedBackListRequest();
        feedBackListRequest.page = page;
        mService.feedbackList(feedBackListRequest.params()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new HandleErrorSubscriber<BaseResponse<FeedbackListContent>>(mView) {
                    @Override
                    public void onGetPayInfoSuccess(BaseResponse<FeedbackListContent> response) {
                        FeedbackListContent content = response.getContent();
                        String count = content.getCount();
                        List<LeaveContentList> list = content.getList();
                        mView.getLoadMoreList(list,count);
                    }
                });*/
    }


}
